package test.yzx.pproject;

import android.animation.AnimatorSet;
import android.animation.ValueAnimator;
import android.os.Bundle;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

    View view1,view2;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.l1);
    //    view1 = findViewById(R.id.v1); view2 = findViewById(R.id.v2);

        ValueAnimator anim1 = ValueAnimator.ofInt(0, 300).setDuration(300);
        anim1.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            public void onAnimationUpdate(ValueAnimator animation) {
                view1.setTranslationX((int) animation.getAnimatedValue());
            }
        });

        ValueAnimator anim2 = ValueAnimator.ofInt(0, 300).setDuration(300);
        anim2.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            public void onAnimationUpdate(ValueAnimator animation) {
                view2.setTranslationX((int) animation.getAnimatedValue());
            }
        });


        //先play1，之后play2
        set.playSequentially(anim1, anim2);
        //先play1，之后play2
        //set.play(anim2).after(anim1);
        new Handler().postDelayed(new Runnable() {
            public void run() {
                set.start();
            }
        }, 800);

    }


    private AnimatorSet set = new AnimatorSet();

    // static 不是上来才执行... 是用到这个类了 , 才加载这个类 , 然后是static..   用到类的变量不管用
    static {
        Toast.makeText(YApplication.getInstance(), "lalal", Toast.LENGTH_SHORT).show();
    }

    public static int test(){
        Toast.makeText(YApplication.getInstance(), "fffffffffffff", Toast.LENGTH_SHORT).show();
        return 1;
    }

}
